package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.search.service.SearchService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("/api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    //手动上级到es
    @Operation(summary = "手动同步专辑到es")
    @PostMapping("/onSale/{albumId}")
    public Result OnSaleAlbum(@PathVariable Long albumId){
        searchService.OnSaleAlbum(albumId);
        return Result.ok();
    }
    @GetMapping("/batch/albuminfo/down")
    public Result batchAlbumdownSale() {
        searchService.batchAlbumDownSale();
        return Result.ok();
    }
    @DeleteMapping("/down/{albumId}")
    public Result downSaleAlbum(@PathVariable(value = "albumId") Long albumId) {
        searchService.downSaleAlbum(albumId);
        return Result.ok();
    }

    /**
     * 批量上架
     */
    @GetMapping("/batch/albuminfo")
    public Result batchAlbumOnSale() {
        for (int i = 1; i <= 1577; i++) {
            searchService.OnSaleAlbum((long) i);
        }
        return Result.ok();
    }


    //Request URL: http://192.168.37.1:8500/api/search/albumInfo/channel/1
    @Operation(summary = "根据一级分类id获取频道列表")
    @GetMapping("/channel/{c1Id}")
    public Result channel(@PathVariable(value = "c1Id") Long c1Id){
        List<Map<String,Object>> channel= searchService.channel(c1Id);
        return Result.ok(channel);
    }

    //http://192.168.37.1:8500/api/search/albumInfo/1429

    @GetMapping("/{albumId}")
    public Result albumInfoGet(@PathVariable(value = "albumId") Long albumId){
        Map<String,Object>map = searchService.albumInfoGet(albumId);
        return Result.ok(map);
    }

}

